package com.xunshibao.tutor.concern;

import org.springframework.stereotype.Repository;

import com.xunshibao.core.dao.BaseDAO;
import com.xunshibao.tutor.po.TutorDate;
import com.xunshibao.tutor.po.TutorDate.Status;

/**
 * 家教信息关注，操作了w_tdate表
 * 
 * @author zhanyuny
 * 
 */
@Repository
public class ConcernDaoImpl {
	private static final String INSERT = "insert into w_tdate(tid, uid, status, dt) values(?,?,?,?)";
	private static final String IS_CONCERNED = "select 'a' from w_tdate where tid=? and uid=? and status=?";
	private static final String CANCLE_CONCERN = "update w_tdate set status=? where tid=? and uid=?";
	private static final String GET_CONCERN = "select tid, uid from w_tdate where tid=? and uid=?";

	public int save(TutorDate date) {
		return BaseDAO.execute(INSERT,
				new Object[] { date.getTid(), date.getUid(), date.getStatus(),
						date.getDt() });
	}

	public int update(String[] properties, Object[] values, String condition) {
		return BaseDAO.update(TutorDate.TB, properties, values, condition);
	}
	
	public TutorDate getTutorDate(Long infoId, Long userId) {
		return BaseDAO.queryForObject(TutorDate.class, GET_CONCERN, new Object[]{infoId, userId,});
	}

	public boolean isConcerned(Long infoId, Long userId) {
		Object obj = BaseDAO.queryOneRowOneCol(IS_CONCERNED, new Object[] {
				infoId, userId, Status.ENABLE.value() });
		if (obj != null) {
			return true;
		} else {
			return false;
		}
	}

}
